<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;
            overflow: hidden;
        }

        .sub {
            width: 100px;
            height: 100px;
            margin: 50px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="sub"></div>
    </div>
</body>
<script>
    // 鼠标相关的事件
    // onclick    鼠标单击(鼠标左键)
    // ondblclick 鼠标双击(鼠标左键)
    // onmousedown 鼠标按下 (左键 中键 右键 侧键)

    var box = document.getElementsByClassName("box")[0];

    // onmouseover onmouseout的问题
    // 给父元素绑定onmouseover onmouseout事件,滑过子代元素时,会先触发划出,再触发划入

    // box.onmouseover = function () {
    //     console.log("鼠标划入box");
    // }
    // box.onmouseout = function () {
    //     console.log("鼠标划出box");
    // }

    // 怎么解决?
    // 官方提供了了 onmouseenter onmouseleave 替换 onmouseover onmouseout

    box.onmouseenter = function () {
        console.log("鼠标划入box");
    }
    box.onmouseleave = function () {
        console.log("鼠标划出box");
    }

</script>

</html>